package com.bootdo.goods.service.impl;

import com.bootdo.common.domain.Tree;
import com.bootdo.common.utils.BuildTree;
import com.bootdo.system.domain.DeptDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.goods.dao.GoodstypeDao;
import com.bootdo.goods.domain.GoodstypeDO;
import com.bootdo.goods.service.GoodstypeService;



@Service
public class GoodstypeServiceImpl implements GoodstypeService {
	@Autowired
	private GoodstypeDao goodstypeDao;
	
	@Override
	public GoodstypeDO get(Integer id){
		return goodstypeDao.get(id);
	}
	
	@Override
	public List<GoodstypeDO> list(Map<String, Object> map){
		return goodstypeDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return goodstypeDao.count(map);
	}
	
	@Override
	public int save(GoodstypeDO goodstype){
		return goodstypeDao.save(goodstype);
	}
	
	@Override
	public int update(GoodstypeDO goodstype){
		return goodstypeDao.update(goodstype);
	}
	
	@Override
	public int remove(Integer id){
		return goodstypeDao.remove(id);
	}
	
	@Override
	public int batchRemove(Integer[] ids){
		return goodstypeDao.batchRemove(ids);
	}

	@Override
	public Tree<GoodstypeDO> getTree() {
		List<Tree<GoodstypeDO>> trees = new ArrayList<Tree<GoodstypeDO>>();
		List<GoodstypeDO> goodstypeDOList = goodstypeDao.list(new HashMap<String, Object>(16));
		for (GoodstypeDO goodstypeDO : goodstypeDOList) {
			Tree<GoodstypeDO> tree = new Tree<GoodstypeDO>();
			tree.setId(goodstypeDO.getId().toString());
			tree.setParentId(goodstypeDO.getParentId().toString());
			tree.setText(goodstypeDO.getTypename());
			Map<String, Object> state = new HashMap<>(16);
			state.put("opened", true);
			tree.setState(state);
			trees.add(tree);
		}
		// 默认顶级菜单为０，根据数据库实际情况调整
		Tree<GoodstypeDO> t = BuildTree.build(trees);
		return t;
	}

}
